#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>

int sum;
void* runner01(void * param);
void* runner02(void * param);

int main (int argc, char * argv[])
{
    sum = 0;
    pthread_t tid01;
    pthread_t tid02;
    pthread_attr_t attr;
    pthread_attr_init(&attr);
    pthread_create(&tid01, &attr, runner01, NULL);
    pthread_create(&tid02, &attr, runner02, NULL);

//    pthread_join(tid01, NULL);
//    pthread_join(tid02, NULL);
    puts("main to exit");
    exit(0);
    puts("main exitted");
}

void * runner01(void * param)
{
    for (int i = 1;; i++)
    {
        ++sum;
//if (i > 1e7)
        //pthread_exit(0);
        printf("[Thread 1] sum = %d\n", sum);
    }

}

void * runner02(void * param)
{
    for (int i = 1;; i++)
    {
        --sum;
        printf("[Thread 2] sum = %d\n", sum);
    }
}
